from pymongo import MongoClient
import time
import 获取牌

def check_user_sequences(username):
    # 连接到MongoDB（确保MongoDB服务已在本地运行）
    client = MongoClient("mongodb://192.168.168.110:27017/")

    while True:
        # 选择数据库
        db = client['data']

        # 检查sequence为3的用户
        seq3_user = db.user.find_one({"sequence": 2})
        if seq3_user:
            # 检查sequence为1和2的用户的cpcg值
            seq1_user = db.user.find_one({"sequence": 1})
            seq2_user = db.user.find_one({"sequence": 2})

            # 条件判断
            if (seq1_user and seq1_user.get("cpcg") == True) and (seq2_user and seq2_user.get("cpcg") == True):
                print("轮到你出牌了。")
                获取牌.user_gain(username)
                break  # 满足条件后退出循环
            else:
                print("cpcg值未满足出牌条件。")
        else:
            print("未找到sequence为3的用户。")

        # 等待一段时间再进行下一次检查
        time.sleep(5)

    # 关闭MongoDB连接
    client.close()

if __name__ == "__main__":
    username = "lishi"  # 指定要查询的用户名
    check_user_sequences(username)  # 检查用户状态
